// pages/organization/index/index.js
import {
  BASE_URL
} from '../../../constant/index'
import {
  getRidingEventListApi
} from '../../../https/ridingEvents'
import {
  generateClassifyList
} from '../../../utlis/utils'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    BASE_URL,
    classifyList: generateClassifyList(), // 分类标签
    classifyIndex: 0,
    page: 1,
    limit: 100,
    total: 100,
    ridingList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // this.getRidingEventList()
  },
  onShow(){

    this.getRidingEventList()
  },
  // 获取约骑列表
  async getRidingEventList() {
    const {
      page,
      limit,
      total
    } = this.data
    const classifyList = this.data.classifyList
    const classifyIndex = this.data.classifyIndex
    const {
      fullDate
    } = classifyList[classifyIndex] 
    console.log(fullDate)
    const getRes = await getRidingEventListApi({
      page,
      limit,
      fullDate
    })
    console.log(getRes)

    if (getRes.code == 200) {
      this.setData({
        // page: getRes.data.page + 1,
        total: getRes.data.total,
        ridingList: getRes.data.list
      })
    }
  },

  // 切换轮播图
  toggleSwiper(e) {
    console.log(e)
    const index = e.currentTarget.dataset.index
    this.setData({
      classifyIndex: index
    });
    this.getRidingEventList()
    
  },
  // 跳转详情页面
  gotoDetail(e) {
    console.log(e)
    const docid = e.currentTarget.dataset.docid
    wx.navigateTo({
      url: '../detail/index?docid=' + docid,
    })
  },
  // 跳转组织骑行
  gotoManager(e) {
    wx.navigateTo({
      url: '../manager/index',
    })
  },
  // 跳转参加的
  gotoJoin(e) {
    wx.navigateTo({
      url: '../join/index',
    })
  }
})